<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://xmlns.jcp.org/jsf/html"
	xmlns:f="http://xmlns.jcp.org/jsf/core"
	xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
	xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
	xmlns:mywidgets="http://xmlns.jcp.org/jsf/composite/widgets"
>

<ui:composition template="/templates/photoTemplate.xhtml">

	<ui:define name="title">Administration</ui:define>

	<f:metadata>
		<f:viewParam name="id"
			value="#{reservationStatusController.reservationId}"
		/>
		<f:event listener="#{reservationStatusController.lookupReservation()}"
			type="preRenderView"
		/>
	</f:metadata>

	<ui:define name="body">
	
		#{reservationController.loadExistingReservationById()}
	
		<h1>Reservation</h1>
		
		<h:messages/>
		
		<h:panelGroup id="panelRes" layout="block">

			<p class="betweenSections" />
			
			<h:panelGroup id="panelForm" layout="block">

			<div class="process">
			
				
				<h:panelGroup rendered="#{reservationStatusController.new}">
				
					<span class="processStep">
						<div class="processStepTitle">status: new</div>
						<div class="processStepText">
							This is the initial state.
							<p />
							Press "accept" to accept the selected date. An Email is sent to
							the customer with instructions about the up-front payment.
						</div>
					</span>
					<span class="processAction"> 
						<h:form>
							<h:inputHidden
								value="#{reservationStatusController.reservationId}"
							/>
							<h:commandButton
								action="#{reservationStatusController.updateReservationState('ACCEPTED')}"
								rendered="#{reservationStatusController.new}"
								styleClass="processButton" value="accept"
								onclick="return confirm('Do you really want to accept this date and customer?')"
							>
								<f:setPropertyActionListener
									target="#{reservationStatusController.reservationId}"
									value="#{reservationStatusController.reservationId}"
								/>
								<f:ajax execute="@form" render="panelForm" />
							</h:commandButton>
						</h:form>
					</span>
					
				</h:panelGroup>
				
				<h:panelGroup rendered="#{reservationStatusController.accepted}">				
					<span class="processStep">
						<div class="processStepTitle">status: accepted</div>
						<div class="processStepText">
							We are waiting for the up-front payment.
							<p />
							If up-front payment is received, press confirm. An
							Email-confirmation will be sent to the guest including the door
							lock key. Also, the cleaning lady receives the cleaning date.
						</div>
					</span>
					<span class="processAction"> 
						<h:form>
							<h:inputHidden
								value="#{reservationStatusController.reservationId}"
							/>
							<h:commandButton
								action="#{reservationStatusController.updateReservationState('CONFIRMED')}"
								rendered="#{reservationStatusController.accepted}"
								styleClass="processButton" value="confirm"
								onclick="return confirm('Do you really want to confirm the payment arrival?')"
							>
								<f:setPropertyActionListener
									target="#{reservationStatusController.reservationId}"
									value="#{reservationStatusController.reservationId}"
								/>
								<f:ajax execute="@form" render="panelForm" />
							</h:commandButton>
						</h:form>						
					</span>					
				</h:panelGroup>			


				<h:panelGroup rendered="#{reservationStatusController.confirmed}">
					<span class="processStep">
						<div class="processStepTitle">status: confirmed</div>
						<div class="processStepText">
							The up-front payment is received. The cleaning lady is assigned.
							The contract is legally binding.
							<p />
							If everything worked out well and the cleaning lady reports no
							issues, press settle to close the case.
						</div>
					</span>
					<span class="processAction"> 
						<h:form>
							<h:inputHidden
								value="#{reservationStatusController.reservationId}"
							/>
							<h:commandButton
								action="#{reservationStatusController.updateReservationState('SETTLED')}"
								rendered="#{reservationStatusController.confirmed}"
								styleClass="processButton" value="settle"
								onclick="return confirm('Do you really want to settle this rental case? It cannot be revoked.')"
							>
								<f:setPropertyActionListener
									target="#{reservationStatusController.reservationId}"
									value="#{reservationStatusController.reservationId}"
								/>
								<f:ajax execute="@form" render="panelForm" />
							</h:commandButton>
						</h:form>
					</span>
				</h:panelGroup>

				<h:panelGroup rendered="#{reservationStatusController.settled}">
					<span class="processStep">
						<div class="processStepTitle">status: settled</div>
						<div class="processStepText">
							This rental case is closed.
							<p />
							No further actions can be invoked. User data remains in the
							database.
						</div>
					</span>
				</h:panelGroup>

				<h:panelGroup
					rendered="#{not reservationStatusController.settled and not reservationStatusController.rejected}"
				>
					<span class="processAction"> 
						<h:form>
							<h:inputHidden
								value="#{reservationStatusController.reservationId}"
							/>
							<h:commandButton
								action="#{reservationStatusController.updateReservationState('REJECTED')}"
								rendered="#{not reservationStatusController.settled}"
								styleClass="processButton" value="reject"
								onclick="return confirm('CAUTION! Do you really want to reject this visitor\'s rental request? The reservation will be deleted and the visitor will be informed of this rejection!')"
							>
								<f:setPropertyActionListener
									target="#{reservationStatusController.reservationId}"
									value="#{reservationStatusController.reservationId}"
								/>
								<f:ajax execute="@form" render="panelForm" />
							</h:commandButton>
						</h:form>
					</span>
				</h:panelGroup>

				<h:panelGroup rendered="#{reservationStatusController.rejected}">
					<span class="processStep">
						<div class="processStepTitle">status: rejected</div>
						<div class="processStepText">
							This request has not been confirmed.
							<p />
							Others may book this time spot.
						</div>
					</span>
				</h:panelGroup>
			</div>
			</h:panelGroup>


			<p class="betweenSections" />

			<!-- DATA OF RESERVATION -->

			<div>
				<h:outputText value="#{reservationController.reservation.startDate}">
					<f:convertDateTime pattern="d. MMMM yyyy" />
				</h:outputText>
				&nbsp;-&nbsp;
				<h:outputText value="#{reservationController.reservation.endDate}">
					<f:convertDateTime pattern="d. MMMM yyyy" />
				</h:outputText>
			</div>
			<div>#{reservationController.reservation.numberOfGuests} Guests</div>

			<h2>Meta Data</h2>
			<div>
				Received:
				<h:outputText
					value="#{reservationController.reservation.dateCreated}"
				>
					<f:convertDateTime pattern="d. MMMM yyyy  HH:mm:ss" />
				</h:outputText>
			</div>
			<div>
				Modified:
				<h:outputText
					value="#{reservationController.reservation.dateModified}"
				>
					<f:convertDateTime pattern="d. MMMM yyyy HH:mm:ss" />
				</h:outputText>
			</div>
			<div>
				Reservation ID:
				<h:outputText value="#{reservationController.reservation.id}" />
			</div>
			<div>
				GTC ID:
				<h:outputText value="#{reservationController.reservation.GTC}" />
			</div>

			<h2>Costs</h2>

			<div>
				<strong><h:outputText
						value="#{reservationController.reservation.costs.totalCosts}"
					>
						<f:convertNumber type="currency" currencySymbol="€"
							maxFractionDigits="2"
						/>
					</h:outputText> Total Costs</strong>
			</div>
			<div>
				<h:outputText
					value="#{reservationController.reservation.costs.reservationCosts}"
				>
					<f:convertNumber type="currency" currencySymbol="€"
						maxFractionDigits="2"
					/>
				</h:outputText>
				Renting Costs
			</div>
			<div>
				<h:outputText
					value="#{reservationController.reservation.costs.cleaningFee}"
				>
					<f:convertNumber type="currency" currencySymbol="€"
						maxFractionDigits="2"
					/>
				</h:outputText>
				Cleaning Fee
			</div>
			<div>
				<h:outputText
					value="#{reservationController.reservation.costs.vatAmount}"
				>
					<f:convertNumber type="currency" currencySymbol="€"
						maxFractionDigits="2"
					/>
				</h:outputText>
				Tax
			</div>

			<h2>Personal Details</h2>

			<div>#{reservationController.reservation.tenant.givenname}
				#{reservationController.reservation.tenant.surname}</div>
			<div>#{reservationController.reservation.tenant.appartment}</div>
			<div>#{reservationController.reservation.tenant.streetAndNumber}</div>
			<div>#{reservationController.reservation.tenant.postalCode}
				#{reservationController.reservation.tenant.city}</div>
			<div>#{reservationController.reservation.tenant.countryCode}</div>

			<p class="betweenSections" />

			<div>#{reservationController.reservation.tenant.email}</div>
			<div>#{reservationController.reservation.tenant.mobile}</div>

			<p class="betweenSections" />

			<div>#{reservationController.reservation.initialReservationComment}</div>

			<p class="betweenSections" />

			<h2>Geo Info</h2>

			<div>#{reservationController.reservation.geoInfo.ip}</div>
			<div>#{reservationController.reservation.geoInfo.zipCode}</div>
			<div>#{reservationController.reservation.geoInfo.city}</div>
			<div>#{reservationController.reservation.geoInfo.regionName}</div>
			<div>#{reservationController.reservation.geoInfo.countryName},
				#{reservationController.reservation.geoInfo.countryCode}</div>


		</h:panelGroup>

		<h:panelGroup
			rendered="#{not reservationController.hasExistingReservation()}"
		>
			No reservation exists with ID <h:outputText value="#{param['id']}" />.
		</h:panelGroup>

		<p class="betweenSections" />

		<ui:debug />


	</ui:define>
</ui:composition>
</html>
